package br.com.gsc.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import br.com.gsc.model.tableMapping.Product;
import br.com.gsc.model.tableMapping.Topic;
import br.com.gsc.repository.objRepos.ProductRepository;

@Controller
@RequestMapping("/{companyId}/produto/**")
public class ProductController {

	@Autowired
	ProductRepository pRepo;
	
	@RequestMapping(value="/{companyId}/produto/{productId}",method = RequestMethod.GET)
	public ModelAndView showPage(@PathVariable("productId") long prodId, @PathVariable("companyId") long compId){
		Product prod = pRepo.findTProductByID(prodId);
		prod.getListOfTopics().size();
		List<Topic> lista = prod.getListOfTopics();
		Topic topic = new Topic();
		ModelAndView model = new ModelAndView("produto");
		model.addObject("company", compId);
		model.addObject("product", prodId);
		model.addObject("topics",lista);
		model.addObject("topic",topic);
		model.addObject("logged",SecurityContextHolder.getContext().getAuthentication().getName());
		return model;
	}
	
//	@RequestMapping(method = RequestMethod.POST)
//	public ModelAndView showPagePost(){
//		Product prod = pRepo.findTProductByID((long) 1);
//		prod.getListOfTopics().size();
//		List<Topic> lista = prod.getListOfTopics();
//		Topic topic = new Topic();
//		ModelAndView model = new ModelAndView("produto");
//		model.addObject("topics",lista);
//		model.addObject("topic",topic);
//		model.addObject("logged",SecurityContextHolder.getContext().getAuthentication().getName());
//		return model;
//	}
}
